home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / docs / doc2rnh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-20  |  8.8 KB  |  369 lines

  1. #ifndef lintÌ*™)ø&¨p,Sid = "$Id: doc2rnh.c,v 1.7 1998/11/20 12:16:15 lhecking Exp $";
  2. #endif
  3.  
  4. /* GNUPLOT - doc2rnh.c */
  5.  
  6. /*[
  7.  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the complete modified source code.  Modifications are to
  17.  * be distributed as patches to the released version.  Permission to
  18.  * distribute binaries produced by compiling modified sources is granted,
  19.  * provided you
  20.  *   1. distribute the corresponding source modifications from the
  21.  *    released version in the form of a patch file along with the binaries,
  22.  *   2. add special version identification to distinguish your version
  23.  *    in addition to the base release version number,
  24.  *   3. provide your name and address as the primary contact for the
  25.  *    support of your modified version, and
  26.  *   4. retain our contact information in regard to use of the base
  27.  *    software.
  28.  * Permission to distribute the released version of the source code along
  29.  * with corresponding source modifications in the form of a patch file is
  30.  * granted with same provisions 2 through 4 for binary distributions.
  31.  *
  32.  * This software is provided "as is" without express or implied warranty
  33.  * to the extent permitted by applicable law.
  34. ]*/
  35.  
  36. /*
  37.  * doc2rnh.c  -- program to convert Gnuplot .DOC format to 
  38.  *               Digital Standard Runoff for VMS HELP files
  39.  *               (gnuplot.doc, including the terminal documentation
  40.  *                is no longer formated for VMS HELP by default)
  41.  * 
  42.  * From hlp2ms by Thomas Williams 
  43.  *
  44.  * Modified by Russell Lang, 2nd October 1989
  45.  * to make vms help level 1 and 2 create the same ms section level.
  46.  *
  47.  * Modified to become doc2ms by David Kotz (David.Kotz@Dartmouth.edu) 12/89
  48.  * Added table and backquote support.
  49.  *
  50.  * Adapted from doc2ms.c (the unix 'runoff' text-processor)
  51.  * by Lucas Hart 3/97
  52.  *
  53.  * right margin is adjusted two spaces for each level to compensate 
  54.  * for the indentation by VMS HELP
  55.  *
  56.  * the page width can be adjusted by changing the value of DSR_RM 
  57.  * usage: $ MCR []doc2rnh gnuplot.doc gnuplot.rnh
  58.  *        $ RUNOFF gnuplot.rnh
  59.  *
  60.  * 
  61.  */
  62.  
  63. #ifdef HAVE_CONFIG_H
  64. # include "config.h"
  65. #endif
  66.  
  67. #include "ansichek.h"
  68. #include "stdfn.h"
  69. #include "doc2x.h"
  70.  
  71. extern boolean single_top_level;
  72.  
  73. #define LINE_SKIP        3
  74. #define DSR_RM        70
  75.  
  76. void init __PROTO((FILE *));
  77. void convert __PROTO((FILE *, FILE *));
  78. void process_line __PROTO((char *, FILE *));
  79. void section __PROTO((char *, FILE *));
  80. void putrnh __PROTO((char *, FILE *));
  81. void putrnh_ __PROTO((char *, FILE *));
  82. void finish __PROTO((FILE *));
  83.  
  84. static boolean intable = FALSE;
  85. static boolean rnh_table = FALSE;
  86. static boolean initial_entry = FALSE;
  87.  
  88. int main(argc, argv)
  89. int argc;
  90. char **argv;
  91. {
  92.     FILE *infile;
  93.     FILE *outfile;
  94.     infile = stdin;
  95.     outfile = stdout;
  96.  
  97.     single_top_level = TRUE;
  98.  
  99.     if (argc > 3) {
  100.     fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
  101.     exit(EXIT_FAILURE);
  102.     }
  103.     if (argc >= 2) {
  104.     if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
  105.         fprintf(stderr, "%s: Can't open %s for reading\n",
  106.             argv[0], argv[1]);
  107.         exit(EXIT_SUCCESS);
  108.     }
  109.     }
  110.     if (argc == 3) {
  111.     if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
  112.         fprintf(stderr, "%s: Can't open %s for writing\n",
  113.             argv[0], argv[2]);
  114.         exit(EXIT_FAILURE);
  115.     }
  116.     }
  117.     init(outfile);
  118.     convert(infile, outfile);
  119.     finish(outfile);
  120.     exit(EXIT_SUCCESS);
  121. }
  122.  
  123.  
  124. void init(b)
  125. FILE *b;
  126. {
  127.     /*     */
  128.     (void) fputs(".no paging\n\
  129. .no flags all\n\
  130. .left margin 1\n\
  131. .right margin 70\n\
  132. .no justify\n", b);
  133. }
  134.  
  135.  
  136. void convert(a, b)
  137. FILE *a, *b;
  138. {
  139.     static char line[MAX_LINE_LEN+1];
  140.  
  141.     while (get_line(line, sizeof(line), a)) {
  142.     process_line(line, b);
  143.     }
  144. }
  145.  
  146. void process_line(line, b)
  147. char *line;
  148. FILE *b;
  149. {
  150.     switch (line[0]) {        /* control character */
  151.     case '?':{            /* interactive help entry */
  152.         break;        /* ignore */
  153.     }
  154.     case '@':{            /* start/end table */
  155.         if (rnh_table) {
  156.         (void) fputs(".end literal\n", b);
  157.         rnh_table = FALSE;
  158.         intable = FALSE;
  159.         } else {
  160. /*                       (void) fputs(".literal\n",b);  */
  161.         intable = TRUE;
  162.         rnh_table = FALSE;
  163.         initial_entry = TRUE;
  164.         }
  165.         /* ignore rest of line */
  166.         break;
  167.     }
  168.     case '^':{            /* html table entry */
  169.         break;        /* ignore */
  170.     }
  171.     case '#':{            /* latex table entry */
  172.         break;        /* ignore */
  173.     }
  174.     case '%':{            /* troff table entry */
  175.         break;        /* ignore */
  176.     }
  177. #if 0
  178. /* 'C' is taken care of by termdoc.c */
  179.     case 'C':{            /*  new Comment designator */
  180.         break;        /* ignore */
  181.     }
  182. #endif
  183.     case '\n':            /* empty text line */
  184.     case ' ':{            /* normal text line */
  185.  
  186. /* most tables are simple; no flags means no protected characters
  187.  * other than period (command indicator) in first column
  188.  *
  189.  * However, for ease of maintainence, two tables have sublevels
  190.  * and descriptions, corresponding to the printed table entries, 
  191.  * encapsulated by the table markers.  Therefore we need to
  192.  * do some more work.
  193.  *
  194.  * Doc2hlp just ignores the table headings and treats
  195.  * lower levels irrespectively, but we need to break
  196.  * the level designators out of the table format.   
  197.  *
  198.  *  The first entry in a table will have either 
  199.  *     - a level number in the first column => remainder of text in
  200.  *                                             table is help text 
  201.  *     - spaces in the first two columns => rest of text is literal 
  202.  *                                          to be placed in table format
  203.  *
  204.  */
  205.  
  206. /* use the "cleartext" table or other text in tables */
  207.  
  208. /*                if (intable)  { /* its already literal */
  209.         if (rnh_table) {    /* its a literal */
  210.         putrnh(line + 1, b);
  211.         break;
  212.         }
  213.         switch (line[1]) {
  214.         case ' ':{
  215.             if ((intable) && (initial_entry)) {
  216.             rnh_table = TRUE;
  217.             initial_entry = FALSE;
  218.             fputs(".literal\n", b);
  219.             putrnh(line + 1, b);
  220.             break;
  221.             }
  222.             /* verbatim mode */
  223.             fputs(".literal\n", b);
  224.             putrnh(line + 1, b);
  225.             fputs(".end literal\n", b);
  226.             break;
  227.         }
  228.  
  229. /*
  230.  *  "." in first column is the DSR command character;
  231.  *  therefore, include the preceeding " "
  232.  */
  233.         case '.':{
  234.             putrnh(line, b);
  235.             break;
  236.         }
  237.         default:{
  238.             if (line[0] == '\n')
  239.             fputs(".skip\n", b);    /* totally blank line */
  240.             else
  241.             putrnh(line + 1, b);
  242.             break;
  243.         }
  244.         break;
  245.         }
  246.         break;
  247.     }
  248.     default:{
  249.         if (isdigit((int) line[0])) {    /* start of section */
  250.  
  251. /* some HELP text is surrounded by table flags */
  252. /* doc2rnh will ignore the flags */
  253.  
  254.         if (intable) {
  255.             if (initial_entry) {
  256.             initial_entry = FALSE;
  257.             rnh_table = FALSE;
  258.             }
  259.         }
  260.         section(line, b);
  261.         } else
  262.         fprintf(stderr, "unknown control code '%c' in column 1\n",
  263.             line[0]);
  264.         break;
  265.     }
  266.     }
  267. }
  268.  
  269.  
  270. /* process a line with a digit control char */
  271. /* starts a new [sub]section */
  272. /* We want to retain section number, so its simpler than w/ TeX or roff */
  273.  
  274. void section(line, b)
  275. char *line;
  276. FILE *b;
  277. {
  278.     int sh_i;
  279.     static int old = 1;
  280. /*  
  281.    (void) sscanf(line,"%d",&sh_i);
  282.    *
  283.    * check to make sure this works with terminals also
  284.  */
  285.     sh_i = atoi(line);
  286.  
  287.     if (sh_i > old) {
  288.     do
  289.         if (old != 1)    /* this line added by rjl */
  290.         (void) fputs(".rm-2\n", b);
  291.     while (++old < sh_i);
  292.     } else if (sh_i < old) {
  293.     do
  294.         if (sh_i != 1)    /* this line added by rjl */
  295.         (void) fputs(".rm+2\n", b);
  296.     while (--old > sh_i);
  297.     }
  298.     /* added by dfk to capitalize section headers */
  299.     /* Header name starts at [2] */
  300. /* omit for online documentation 
  301.  *    if (islower(line[2]))
  302.  *       line[2] = toupper(line[2]);
  303.  */
  304.     old = sh_i;
  305.  
  306.     (void) fputs(".indent -1;\n", b);
  307.     (void) putrnh_(line, b);
  308.     (void) fputs(".br;\n", b);
  309. }
  310.  
  311. /*
  312.  * dummy function in case we need to convert some characters in
  313.  * output string ala doc2tex and doc2ms 
  314.  */
  315.  
  316. void putrnh(s, file)
  317. char *s;
  318. FILE *file;
  319. {
  320.     (void) fputs(s, file);
  321. }
  322.  
  323. /* 
  324.  * LBR$OUTPUT_HELP treats spaces and "/"s as list separators for topics,
  325.  * but they are used in gnuplot.doc for the printed docs; convert to
  326.  * "_" and "|"   Modeled after section heading conversions in doc2tex 
  327.  * and doc2ms. 
  328.  *
  329.  */
  330.  
  331. void putrnh_(s, file)
  332. char *s;
  333. FILE *file;
  334. {
  335.     int i, s_len, last_chr;
  336.  
  337.     s_len = strlen(s);
  338.  
  339.     for (i = s_len - 1; i > 2; i--) {    /* any trailing spaces to drop? */
  340.     if (s[i] != ' ') {
  341.         last_chr = i;
  342.         break;
  343.     }
  344.     }
  345.  
  346.     for (i = 0; i <= last_chr; i++) {
  347.     if (i > 2) {
  348.         switch (s[i]) {
  349.         case ' ':
  350.         (void) fputc('_', file);
  351.         break;
  352.         case '/':
  353.         (void) fputc('|', file);
  354.         break;
  355.         default:
  356.         (void) fputc(s[i], file);
  357.         }
  358.     } else {
  359.         (void) fputc(s[i], file);
  360.     }
  361.     }
  362. }
  363.  
  364. void finish(b)            /* not used */
  365. FILE *b;
  366. {
  367.     return;
  368. }
  369.